#include "../include/json.hpp"
#include <iostream>
#include <fstream>
#include <vector>
#include "../include/AllInOne.hpp"

using namespace std;
using json = nlohmann::json;

json openfile()
{
    ifstream file("./json/input1.json");
    if (!file.is_open())
        cerr << "Failed to open file" << endl;
    json j;
    file >> j;
    file.close();
    return j;
}

int main()
{
    json input = openfile();
    int dim = input["InitialValue"].size();
    double T = input["Time"];
    int p = input["p"];
    int n_steps = input["n_size"];
    vector<double> value;
    for (int i = 0; i < dim; i++)
        value.push_back(input["InitialValue"][i]);
    if (input["Method"] == 6)
    {
        FehlbergEmbeddedRk fe(n_steps, T, value);
        fe.solver();
        fe.error();
    }
    else if (input["Method"] == 7)
    {
        DormandPrinceEmbeddedRK dpe(n_steps, T, value);
        dpe.solver();
        dpe.error();
    }
    else if (input["Method"] == 5)
    {
        GaussLegendreRK glr(n_steps, p, T, value);
        glr.solver();
        glr.error();
    }
    else if (input["Method"] == 4)
    {
        ESDIRK eds(n_steps, T, value);
        eds.solver();
        eds.error();
    }
    else if (input["Method"] == 3)
    {
        ClassicalRK crk(n_steps, T, value);
        crk.solver();
        crk.error();
    }
    else if (input["Method"] == 2)
    {
        BackDifferFormula bdf(n_steps, p, T, value);
        bdf.solver();
        bdf.error();
    }
    else if (input["Method"] == 1)
    {
        AdamsMoultonSolver ams(n_steps, p, T, value);
        ams.solver();
        ams.error();
    }
    else if (input["Method"] == 0)
    {
        AdamsBashforthSolver abs(n_steps, p, T, value);
        abs.solver();
        abs.error();
    }
    return 0;
}